<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::AtomFeedHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::AtomFeedHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M002001">atom_feed</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="AtomFeedHelper/AtomBuilder.html" class="link">ActionView::Helpers::AtomFeedHelper::AtomBuilder</a><br />
Class <a href="AtomFeedHelper/AtomFeedBuilder.html" class="link">ActionView::Helpers::AtomFeedHelper::AtomFeedBuilder</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M002001" class="method-detail">
        <a name="M002001"></a>

        <div class="method-heading">
          <a href="#M002001" class="method-signature">
          <span class="method-name">atom_feed</span><span class="method-args">(options = {}) {|AtomFeedBuilder.new(xml, self, options)| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Full usage example:
</p>
<pre>
  config/routes.rb:
    ActionController::Routing::Routes.draw do |map|
      map.resources :posts
      map.root :controller =&gt; &quot;posts&quot;
    end

  app/controllers/posts_controller.rb:
    class PostsController &lt; ApplicationController::Base
      # GET /posts.html
      # GET /posts.atom
      def index
        @posts = Post.find(:all)

        respond_to do |format|
          format.html
          format.atom
        end
      end
    end

  app/views/posts/index.atom.builder:
    atom_feed do |feed|
      feed.title(&quot;My great blog!&quot;)
      feed.updated((@posts.first.created_at))

      for post in @posts
        feed.entry(post) do |entry|
          entry.title(post.title)
          entry.content(post.body, :type =&gt; 'html')

          entry.author do |author|
            author.name(&quot;DHH&quot;)
          end
        end
      end
    end
</pre>
<p>
The options for <a href="AtomFeedHelper.html#M002001">atom_feed</a> are:
</p>
<ul>
<li><tt>:language</tt>: Defaults to &quot;en-US&quot;.

</li>
<li><tt>:root_url</tt>: The HTML alternative that this feed is doubling for.
Defaults to / on the current host.

</li>
<li><tt>:url</tt>: The URL for this feed. Defaults to the current URL.

</li>
<li><tt>:id</tt>: The id for this feed. Defaults to &quot;<a
href="http://0">tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")</a>}&quot;

</li>
<li><tt>:schema_date</tt>: The date at which the tag scheme for the feed was
first used. A good default is the year you created the feed. See <a
href="http://feedvalidator.org/docs/error/InvalidTAG.html">feedvalidator.org/docs/error/InvalidTAG.html</a>
for more information. If not specified, 2005 is used (as an &quot;I
don&#8216;t care&quot; value).

</li>
<li><tt>:instruct</tt>: Hash of XML processing instructions in the form {target
=&gt; {attribute =&gt; value, }} or {target =&gt; [{attribute =&gt; value,
}, ]}

</li>
</ul>
<p>
Other namespaces can be added to the root element:
</p>
<pre>
  app/views/posts/index.atom.builder:
    atom_feed({'xmlns:app' =&gt; 'http://www.w3.org/2007/app',
        'xmlns:openSearch' =&gt; 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
      feed.title(&quot;My great blog!&quot;)
      feed.updated((@posts.first.created_at))
      feed.tag!(openSearch:totalResults, 10)

      for post in @posts
        feed.entry(post) do |entry|
          entry.title(post.title)
          entry.content(post.body, :type =&gt; 'html')
          entry.tag!('app:edited', Time.now)

          entry.author do |author|
            author.name(&quot;DHH&quot;)
          end
        end
      end
    end
</pre>
<p>
The Atom spec defines five elements (content rights title subtitle summary)
which may directly contain xhtml content if :type =&gt; &#8216;xhtml&#8217;
is specified as an attribute. If so, this helper will take care of the
enclosing div and xhtml namespace declaration. Example usage:
</p>
<pre>
   entry.summary :type =&gt; 'xhtml' do |xhtml|
     xhtml.p pluralize(order.line_items.count, &quot;line item&quot;)
     xhtml.p &quot;Shipped to #{order.address}&quot;
     xhtml.p &quot;Paid by #{order.pay_type}&quot;
   end
</pre>
<p>
<a href="AtomFeedHelper.html#M002001">atom_feed</a> yields an <a
href="AtomFeedHelper/AtomFeedBuilder.html">AtomFeedBuilder</a> instance.
Nested elements yield an <a
href="AtomFeedHelper/AtomBuilder.html">AtomBuilder</a> instance.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002001-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper.rb, line 94</span>
 94:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">atom_feed</span>(<span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
 95:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:schema_date</span>]
 96:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:schema_date</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:schema_date</span>].<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">&quot;%Y-%m-%d&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:schema_date</span>].<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:strftime</span>)
 97:         <span class="ruby-keyword kw">else</span>
 98:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:schema_date</span>] = <span class="ruby-value str">&quot;2005&quot;</span> <span class="ruby-comment cmt"># The Atom spec copyright date</span>
 99:         <span class="ruby-keyword kw">end</span>
100: 
101:         <span class="ruby-identifier">xml</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:xml</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">eval</span>(<span class="ruby-value str">&quot;xml&quot;</span>, <span class="ruby-identifier">block</span>.<span class="ruby-identifier">binding</span>)
102:         <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">instruct!</span>
103:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:instruct</span>]
104:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:instruct</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">target</span>,<span class="ruby-identifier">attrs</span><span class="ruby-operator">|</span>
105:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:keys</span>)
106:               <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">instruct!</span>(<span class="ruby-identifier">target</span>, <span class="ruby-identifier">attrs</span>)
107:             <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:each</span>)
108:               <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr_group</span><span class="ruby-operator">|</span> <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">instruct!</span>(<span class="ruby-identifier">target</span>, <span class="ruby-identifier">attr_group</span>) }
109:             <span class="ruby-keyword kw">end</span>
110:           <span class="ruby-keyword kw">end</span>
111:         <span class="ruby-keyword kw">end</span>
112: 
113:         <span class="ruby-identifier">feed_opts</span> = {<span class="ruby-value str">&quot;xml:lang&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:language</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;en-US&quot;</span>, <span class="ruby-value str">&quot;xmlns&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'http://www.w3.org/2005/Atom'</span>}
114:         <span class="ruby-identifier">feed_opts</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">options</span>).<span class="ruby-identifier">reject!</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^xml/</span>)}
115: 
116:         <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">feed</span>(<span class="ruby-identifier">feed_opts</span>) <span class="ruby-keyword kw">do</span>
117:           <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">id</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:id</span>] <span class="ruby-operator">||</span> <span class="ruby-node">&quot;tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(&quot;.&quot;)[0]}&quot;</span>)
118:           <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">link</span>(<span class="ruby-identifier">:rel</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'alternate'</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'text/html'</span>, <span class="ruby-identifier">:href</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:root_url</span>] <span class="ruby-operator">||</span> (<span class="ruby-identifier">request</span>.<span class="ruby-identifier">protocol</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">host_with_port</span>))
119:           <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">link</span>(<span class="ruby-identifier">:rel</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'self'</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'application/atom+xml'</span>, <span class="ruby-identifier">:href</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:url</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">url</span>)
120: 
121:           <span class="ruby-keyword kw">yield</span> <span class="ruby-constant">AtomFeedBuilder</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">options</span>)
122:         <span class="ruby-keyword kw">end</span>
123:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>